package com.ruoyi.study.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.study.domain.StyImag;
import com.ruoyi.study.service.IStyImagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * imageController
 * 
 * @author dwb
 * @date 2024-09-02
 */
@RestController
@RequestMapping("/imag")
public class StyImagController extends BaseController
{
    @Autowired
    private IStyImagService styImagService;

    /**
     * 查询image列表
     */
    @RequiresPermissions("study:imag:list")
    @GetMapping("/list")
    public TableDataInfo list(StyImag styImag)
    {
         startPage();
        List<StyImag> list = styImagService.selectStyImagList(styImag);
        return getDataTable(list);
    }

    /**
     * 导出image列表
     */
    @RequiresPermissions("study:imag:export")
    @Log(title = "image", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StyImag styImag)
    {
        List<StyImag> list = styImagService.selectStyImagList(styImag);
        ExcelUtil<StyImag> util = new ExcelUtil<StyImag>(StyImag.class);
        util.exportExcel(response, list, "image数据");
    }

    /**
     * 获取image详细信息
     */
    @RequiresPermissions("study:imag:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(styImagService.selectStyImagById(id));
    }

    /**
     * 新增image
     */
    @RequiresPermissions("study:imag:add")
    @Log(title = "image", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StyImag styImag)
    {
        return toAjax(styImagService.insertStyImag(styImag));
    }

    /**
     * 修改image
     */
    @RequiresPermissions("study:imag:edit")
    @Log(title = "image", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StyImag styImag)
    {
        return toAjax(styImagService.updateStyImag(styImag));
    }

    /**
     * 删除image
     */
    @RequiresPermissions("study:imag:remove")
    @Log(title = "image", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(styImagService.deleteStyImagByIds(ids));
    }
}
